The present invention relates to a graphic processing apparatus, a graphic processing method, a graphic processing program and a program storage medium, which allow high-speed shadowing of three-dimensional objects with simple constitution.
Conventionally, a graphic processing apparatus for performing shadowing of three-dimensional objects includes an apparatus for hidden surface removal by Z-buffer method or scan line Z-buffer method, which adopts a shadowing processing with use of a shadow polygon (see first prior art: JP 01-46915 B).
This graphic processing apparatus includes a frame buffer memory for storing luminance and color data per pixel, a Z-buffer memory for storing a depth Z per pixel, and a counter memory for counting shadow levels. The shadowing of three-dimensional objects is performed as follows.
First, hidden surface removal processing by Z-buffer method is carried out so as not to display planes hidden by foreground objects when seen from a visual point in three-dimensional graphic display. More specifically, the frame buffer memory is filled with a background color and the Z-buffer memory is filled with a maximum depth value. Then, planar polygons ABC, ADB, BDC and ADC of a polyhedron Q in FIG. 12 are converted to visual-point coordinate systems, and for each pixel of each planar polygon, a depth Z (i, j) corresponding to the coordinate (i, j) of the pixel is compared with a depth ZM (i, j) stored in the Z-buffer memory. If ZM (i, j)>Z (i, j), then a value I (i, j) of the frame buffer memory is replaced with color data (including luminance ) C (i, j) of the pixel (i, j) in the polyhedron Q, and a value ZM (i, j) of the Z-buffer memory is replaced with a depth Z (i, j) of the pixel (i, j). If ZM (i, j)≦Z (i, j), then values I (i, j) and ZM (i, j) in the frame buffer memory and Z-buffer memory are not updated.
Thus, planes (planar polygons and a background) hidden by foreground objects (planar polygons) are erased so as not to be displayed. As a result, as shown in FIG. 12, a background that is behind the polyhedron Q when seen from a visual point is replaced with the polyhedron Q.
Next, shadow polygons AEFB, CBFG, AEGC that define a shadow space produced by obstructing a ray of light from a light source P with the polyhedron Q are obtained and converted to visual-point coordinate systems. Then, the converted shadow polygons AEFB, CBFG, AEGC, and the planar polygons ADB, BDC among previously-obtained planar polygons of the polyhedron Q, which are back polygons when seen from the viewpoint of the light source P, are respectively sorted into front polygons and back polygons when seen from a visual point. In this case, the back planar polygon ADC when seen from a visual point is erased by the hidden surface removal processing, and so does not exist in reality. After that, the shadowing processing is performed.
That is, a value Cu (i, j) (shadow level) of the counter memory is set to zero in advance. In this case, an end result of the depth ZM (i, j) obtained by the hidden surface removal processing is stored in the Z-buffer memory. Then, for each pixel of the shadow polygons AEFB, CBFG, AEGC, and the planar polygons ADB, BDC which are back polygons when seen from the viewpoint of the light source P, the depth Z (i, j) of the pixel (i, j) is compared with a value ZM (i, j) in the Z-buffer memory. Based on this comparison result, the shadow level of the counter memory is determined. This processing is performed on every overlap of the shadow polygons and the planar polygons which are back polygons when seen from the viewpoint of the light source P. More specifically,    (a) in the combination of front shadow polygons (AEFB, CBFG) and planar polygons (ADB, BDC),            if ZS (i, j)≦ZM (i, j), then        CU (i, j)←CU (i, j)+1,        if ZS (i, j)>ZM (i, j), then        CU (i, j)=CU (i, j).            (b) in the combination of the back shadow polygon (AEGC) and planar polygons (ADB, BDC),            if ZS (i, j)≦ZM (i, j), then        CU (i, j)←CU (i, j) −1,        if ZS (i, j)>ZM (i, j), then        CU (i, j)=CU (i, j).        
After all the front and back shadow polygons and the planar polygons undergo the above-mentioned processings (a) and (b), a value CU (i, j) of the counter memory is read.
If CU (i, j)≧1, then the following processing is performed:                I (i, j)←CS (shadow color data).        
If CU (i, j)=0, then the following processing is performed:                I (i, j)=I (i, j).        
By the above-stated processings, the shadowing processing is finished. As a result, on the planar polygons ADB, BDC among planar polygons of the polyhedron Q, which are back polygons when seen from the viewpoint of the light source P, there is cast a shadow produced by the planar polygon ABC which is a front polygon.
Further, the shadowing method with use of shadow polygons includes methods using functions of “OpenGL” (see second prior art: “Monthly C MAGAZINE 2001 8” published by SOFTBANK Publishing Inc. in August 2001, Pages 30-32) and “Microsoft DirectX”. In these shadowing methods, a shadow volume that defines a shadow space produced by a ray of light from a light source being obstructed by an object is defined, as well as a stencil buffer is provided for performing a shadowing processing as follows. Provided below is a simple description about the shadowing method by OpenGL.
FIGS. 13A to 13G show operating results of a color buffer and a stencil buffer that are equivalent to the frame buffer in the aforementioned first prior art. It is to be noted that FIGS. 13A to 13D show contents of the color buffer, while FIG. 13F and 13G show contents of the stencil buffer. Like the first prior art, the hidden surface removal processing by Z-buffer method is performed to update the contents of the color buffer and the Z-buffer. As a result, as shown in FIG. 13A, a square planar polygon 101 and a curved planar polygon 102 to be shadowed are stored in the color buffer.
Consequently, first, graphic data on shadow polygons constituting a shadow volume is created so as to form a shadow volume 103 that is present between the planar polygon 101 and a virtual bottom surface (e.g., a plane at Y coordinate “0”) and that consists of a space surrounded by a hexahedron without a ray of light coming therein as shown in FIG. 13 E. Next, front surface data of the shadow volume 103 is written onto the stencil buffer. More particularly, with regard to front-facing shadow polygons facing front when seen from a visual point, a “depth test” is carried out for determining whether or not depth values of the polygons are smaller than Z values in the Z-buffer memory, and as shown in FIG. 13F, a numeral “1” is written in a region of the front-facing shadow polygons where the result of the depth test is “true” in the stencil buffer. As a result, a portion of the front-facing shadow polygons shown in FIG. 13E that is lower than the planar polygon 102 as viewed in the figure is cut off.
Next, back surface data on the shadow volume 103 is written onto the stencil buffer. More particularly, with regard to back-facing shadow polygons facing back when seen from a visual point, the aforementioned depth test is carried out, and a numeral “−1” is added to a region of the back-facing shadow polygons where the result of the depth test is “true” in the stencil buffer. As a result, as shown in FIG. 13G, only a region 104 where the shadowed planar polygon 102 intersects with the shadow volume 103 has a value of “1” in the stencil buffer.
Finally, as shown in FIG. 13D, shadow color data is stored in a region 105 in the color buffer corresponding to the region 104 where the value of the stencil buffer is “1”. Thus, a shadow of the planar polygon 101 is rendered on the curved planar polygon 102.
However, the shadowing method using the aforementioned prior art shadow polygons has a following problem. That is to say, in the graphic processing apparatus disclosed in the first prior art, assume the case where there is an object such as grounds on which a shadow of the polyhedron Q is cast (planar polygon HIJKLDM) in FIG. 12. In this case, as the planar polygon HIJKLDM is a front polygon when seen from the viewpoint of the light source P, a region EFG on the ground (HIJK) is not subjected to shadowing processing. Therefore, it is not possible to place a shadow of the polyhedron Q on the ground, the planar polygon HIJKLDM.
In the shadowing method using OpenGL function disclosed in the second prior art, it is possible to place a shadow of the object on a curved plane on which the shadow of the object should be cast. However, there is a problem that if calculation values of coordinate conversion for polygons have errors, an edge portion of the shadow polygons which is originally not intended to be shadowed is also shadowed.
For example, it is assumed that when the calculation values of coordinate conversion for polygons have errors, the front-facing shadow polygons RS(T)U, U(T)XY and the back-facing shadow polygons RSVW, WVXY, RWYU have deviation, and a side RS of the front-facing shadow polygon RS(T)U is shifted from a line RS of the back-facing shadow polygon RSVW to a left back side when seen from a visual point as shown in FIG. 14. In that case, a lateral portion R′S′SR of the front-facing shadow polygon R′S′T′U′ is positioned outside of the back-facing shadow polygon RSVW. As a result, front surface data “1” written in a region R′S′SR in the stencil buffer remains without being erased by back surface data “−1”, which places a shadow on the region R′S′SR on the lateral side of the front-facing shadow polygon R′S′T′U, which is not intended to be shadowed.